package com.kaishengit.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.kaishengit.entity.User;
import com.kaishengit.service.CommentService;

public class CommentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private CommentService service = new CommentService();
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String method = request.getParameter("method");
		if(method == null || "".equals(method)){
			tosave(request,response);
		}
	}
	private void tosave(HttpServletRequest request, HttpServletResponse response) throws IOException {
		HttpSession session = request.getSession();
		String content = request.getParameter("content");
		String documentId = request.getParameter("id");
		User user =(User) session.getAttribute("user");
		service.save(user,content,documentId);
		response.sendRedirect("document.jspx?method=toDocument&code=1001&id="+documentId);
	}
	
}
